package com.example.chapter03;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.example.chapter03.utils.DateUtil;

//
public class ButtonClickActivity2 extends AppCompatActivity implements View.OnClickListener {

    private TextView tv_result;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_button_click);
        tv_result = findViewById(R.id.tv_result);
        Button btn_click_single = findViewById(R.id.btn_click_single);
        btn_click_single.setOnClickListener(this);

        Button btn_click_public = findViewById(R.id.btn_click_public);
        btn_click_public.setOnClickListener(this);
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.btn_click_public) {
            String desc = String.format("public %s 点击了按钮，%s", DateUtil.getNowDateTime(), ((Button) v).getText());
            tv_result.setText(desc);
        } else if (v.getId() == R.id.btn_click_single) {
            String desc = String.format("single %s 点击了按钮，%s", DateUtil.getNowDateTime(), ((Button) v).getText());
            tv_result.setText(desc);
        }
    }

}